package cn.kgc.bdqn_studentinfomanager.controller;

/**
 * by Shanshui CC on 2020/12/10 14:31
 */

import cn.kgc.bdqn_studentinfomanager.pojo.common.ServerResponse;
import cn.kgc.bdqn_studentinfomanager.pojo.vo.AddUserVo;
import cn.kgc.bdqn_studentinfomanager.service.ManagerService.ManagerService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.config.annotation.CorsRegistry;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.regex.Pattern;

/**
 * 管理员模块
 */
@RestController
@RequestMapping("/admin")
@CrossOrigin
public class ManagerController {

    @Resource
    private ManagerService managerService;

    /**
     * 点击页面时 加载省份列表
     * @return
     */
    @RequestMapping("/loadingProvince")
    public ServerResponse loadingProvince(HttpServletResponse response){
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Cache-Control","no-cache");
        return managerService.loadingProvince();
    }


    /**
     * 管理员添加渠道主管    \  咨询师
     * @param addUserVo
     * @return
     */
    @RequestMapping(value = "/addManagerUser",method = RequestMethod.POST)
    public ServerResponse addManagerUser(AddUserVo addUserVo, HttpServletRequest request,
                                         HttpServletResponse response){
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Cache-Control","no-cache");
        return managerService.addManagerUser(addUserVo,request.getHeader("token"));
    }


    /**
     * 渠道主管添加渠道专员
     * @param addUserVo
     * @param request
     * @return
     */
//    @RequestMapping("/addCommUser")
//    public ServerResponse addCommUser(@RequestBody AddUserVo addUserVo, HttpServletRequest request){
//        return managerService.addCommUser(addUserVo,request.getHeader("token"));
//    }


    /**
     * 管理员添加咨询师
     * @param addUserVo
     * @param request
     * @return
     */
//    @RequestMapping("/addConsultUser")
//    public ServerResponse addConsultUser(@RequestBody AddUserVo addUserVo, HttpServletRequest request,HttpServletResponse response){
//        response.setHeader("Access-Control-Allow-Origin", "*");
//        response.setHeader("Cache-Control","no-cache");
//        return managerService.addConsultUser(addUserVo,request.getHeader("token"));
//    }


    /**
     * 按年 月查询主管部分信息
     * @return
     */
    @RequestMapping("/selectbydate")
    public ServerResponse selectbydate(HttpServletRequest request, HttpServletResponse response, String selectDate){
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Cache-Control","no-cache");


        return managerService.selectbydate(request.getHeader("token"),selectDate);
    }




    /**
     * 进入主管页面时 加载所有专员信息
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/selectExec")
    public ServerResponse selectExec(String userName,HttpServletRequest request, HttpServletResponse response){
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Cache-Control","no-cache");

        System.out.println("userName>?>>>>"+userName);
        if(userName.equals("null") || StringUtils.isBlank(userName)){
            userName = null;
        }
        return managerService.selectExec(userName,request.getHeader("token"));
    }

}
